package com.le.tester.javaThink.fifth.chapter14_StreamingProgramming;

import java.util.stream.*;

import static java.util.stream.LongStream.*;

/**
 * 描述：检测质数
 */

public class Prime {
    public static Boolean isPrime(long n) {
        return rangeClosed(2, (long) (Math.sqrt(n)))
                .noneMatch(o -> n % o == 0);
    }

    public LongStream numbers() {
        return iterate(2, o -> o + 1)
                .filter(Prime::isPrime);
    }

    public static void main(String[] args) {
        new Prime().numbers()
                .limit(10)
                .forEach(o -> System.out.format("%d ", o));
        System.out.println();
        new Prime().numbers()
                .skip(90)
                .limit(10)
                .forEach(o -> System.out.format("%d ", o));
    }

}
